package tereshchuk;

/**
 *
 * @author Pasha
 */
enum MathematicalOperations {

    ADD, SUB, MULT, DIV, ABS
};

public class CalcBase {

    /*
     *    double
     */
    public double add(double Val1, double Val2) {
        return Val1 + Val2;
    }

    public double sub(double Val1, double Val2) {
        return Val1 - Val2;
    }

    public double mult(double Val1, double Val2) {
        return Val1 * Val2;
    }

    public double div(double Val1, double Val2) {
        if (Val2 == 0) {
            return 0;
        } else {
            return Val1 / Val2;
        }
    }

    public double abs(double Val) {
        return Math.abs(Val);
    }

//------------------------------------------------------------------------------

    public double execOperation(MathematicalOperations Opp, double Val1, double Val2) {
        switch (Opp) {
            case ADD:
                return add(Val1, Val2);
            case SUB:
                return sub(Val1, Val2);
            case DIV:
                return div(Val1, Val2);
            case MULT:
                return mult(Val1, Val2);
            case ABS:
                return abs(Val1);
            default:
                return 0;
        }
    }

}
